package com.cv.system.controller.system.role;

import com.cv.framework.common.pojo.PageResult;
import com.cv.framework.common.pojo.Result;
import com.cv.system.controller.system.role.vo.RolePageReqVO;
import com.cv.system.controller.system.role.vo.RoleRespVO;
import com.cv.system.controller.system.role.vo.RoleSaveReqVO;
import com.cv.system.service.role.SystemRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.cv.framework.common.pojo.Result.success;

/**
 * 后台管理系统 - 角色
 *
 * @author Charles_XDXD
 */
@Tag(name = "后台管理系统 - 角色")
@RestController
@RequestMapping("/system/role")
@Validated
public class SystemRoleController {

    @Resource
    private SystemRoleService systemRoleService;

    @GetMapping("/page")
    @Operation(summary = "获得角色分页列表")
    public Result<PageResult<RoleRespVO>> getRolePage(@Valid RolePageReqVO pageReqVO) {
        return success(systemRoleService.getRolePage(pageReqVO));
    }

    @GetMapping("/list")
    @Operation(summary = "获得角色列表")
    public Result<List<RoleRespVO>> getRoleList() {
        return success(systemRoleService.getRoleList());
    }

    @GetMapping("get-user-role")
    @Operation(summary = "获得用户拥有的角色id")
    public Result<Long> getUserRole(Long userId) {
        return success(systemRoleService.getUserRole(userId));
    }

    @PostMapping("set-user-role")
    @Operation(summary = "设置用户的角色id")
    public Result<Boolean> setUserRole(@RequestBody RoleSaveReqVO saveReqVO) {
        systemRoleService.setUserRole(saveReqVO);
        return success(true);
    }

}
